// SPU管理模块接口
import request from "@/utils/request";
import type { HasSpuResData, TrademarkResData, SpuImgResData, SpuSaleAttrResData, HasSaleAttrResData, SpuObj, SkuAddObj, SkuListResData } from "./types";

enum API {
    // 获取已有的SPU数据
    HASSPU_URL = '/admin/product/',
    // 获取已有的品牌数据
    HASTRADEMARK = '/admin/product/baseTrademark/getTrademarkList',
    // 获取某个SPU下全部售卖商品的图片数据
    IMAGE_URL = '/admin/product/spuImageList/',
    // 获取某个SPU下所有销售属性的数据
    SPUSALEATTR_URL = '/admin/product/spuSaleAttrList/',
    // 获取全部的销售属性【颜色、版本、尺码】
    ALLSALEATTR_URL = '/admin/product/baseSaleAttrList',
    // 新增SPU
    ADDSPU_URL = '/admin/product/saveSpuInfo',
    // 修改SPU
    EDITSPU_URL = '/admin/product/updateSpuInfo',
    // 新增SLU
    ADDSKU_URL = '/admin/product/saveSkuInfo',
    // 查看某个Spu的Sku列表
    FINDSKULIST_URL = '/admin/product/findBySpuId/',
    // 删除Spu
    DELETESPU_URL = '/admin/product/deleteSpu/',
}

// 获取某一个三级分类下已有的SPU数据
export const reqHasSpu = (page: number, limit: number, category3Id: string | number): Promise<HasSpuResData> => request({
    url: API.HASSPU_URL + `${page}/${limit}`,
    method: 'GET',
    params: {
        category3Id
    }
});
// 获取已有的全部品牌信息
export const reqHasTrademark = (): Promise<TrademarkResData> => request({
    url: API.HASTRADEMARK,
    method: 'GET'
})
// 获取某个SPU下的商品的图片信息
export const reqSpuImageList = (spuId: number): Promise<SpuImgResData> => request({
    url: API.IMAGE_URL + spuId,
    method: 'GET'
})
// 获取某个SPU下的销售属性的信息
export const reqSpuSaleAttr = (spuId: number): Promise<SpuSaleAttrResData> => request({
    url: API.SPUSALEATTR_URL + spuId,
    method: 'GET'
})
// 获取全部的销售属性
export const reqAllSaleAttr = (): Promise<HasSaleAttrResData> => request({
    url: API.ALLSALEATTR_URL,
    method: 'GET'
})
// 新增或修改SPU
export const reqAddOrEditSpu = (data: SpuObj): any => request({
    // 判断对象中是否存在id来区分是添加还是修改
    url: data.id ? API.EDITSPU_URL : API.ADDSPU_URL,
    method: 'POST',
    data
})
// 新增SKU
export const reqAddSku = (data: SkuAddObj): any => request({
    url: API.ADDSKU_URL,
    method: 'POST',
    data
})
// 查看某个Spu的Sku列表
export const reqSkuListBySpuId = (spuId: number): Promise<SkuListResData> => request({
    url: API.FINDSKULIST_URL + spuId,
    method: 'GET'
})
// 删除SPU
export const reqDeleteSpu = (spuId: number):any => request({
    url: API.DELETESPU_URL + spuId,
    method: 'DELETE'
})